import { Body, Controller, Delete, Get, Param, Post, Put } from "@nestjs/common";
import { wrapResult } from "src/common/r";
import { Address } from "src/entity/address.entity";
import { AddressService } from "src/service/address.service";

@Controller('address')
export class AddressController {
  constructor(private readonly addressService: AddressService) { }

  @Get()
  async getAll() {
    return wrapResult(200, 'success', await this.addressService.findAll())
  }

  @Get(':id')
  async getById(@Param("id") id: number) {
    return wrapResult(200, 'success', await this.addressService.findOne(id))
  }

  @Post()
  async addAddress(@Body() address: Address) {
    return wrapResult(200, 'suucess', await this.addressService.addOne(address))
  }

  @Put()
  async updateOne(@Body() address: Address) {
    return wrapResult(200, 'success', await this.addressService.updateOne(address))
  }

  @Delete(':id')
  async removeOne(@Param('id') id: number) {
    return wrapResult(200, 'success', await this.addressService.remove(id))
  }
}